package lab02.test23;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

/**
 * Created by 123 on 2017/10/30.
 */
public class Test23 {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
        Calendar cal2 = Calendar.getInstance();
        //cal.add(Calendar.DAY_OF_MONTH, -1);//取当前日期的前一天.
       // cal.add(Calendar.DAY_OF_MONTH, +1);//取当前日期的后一天.

        Scanner sc =new Scanner(System.in);//从键盘输入日期

        int Y,M,D;

        System.out.println("生日年份:");
        Y=sc.nextInt();

        System.out.println("生日月份:");
        M=sc.nextInt();

        System.out.println("生日号数:");
        D=sc.nextInt();

        cal.set(Y,M-1,D);//将输入的转换为日期型//为什么月份要减一？

        int birthweek=cal.get(Calendar.DAY_OF_WEEK);//获得星期几
        int birthday=cal.get(Calendar.DAY_OF_YEAR);//获得是一年中第多少天


        System.out.println("您的生日为星期"+(birthweek-1));//因为从星期天开始，所以要减一
        System.out.println("第"+birthday+"天");

//通过格式化输出日期
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println("Today is:"+format.format(Calendar.getInstance().getTime()));



        int today=cal2.get(Calendar.DAY_OF_YEAR);
        System.out.println(today);
                //cal.get(Calendar.DAY_OF_YEAR);
        if (birthday>today ) {
            System.out.println("距离我的生日还有" + (birthday - today) + "天");
        } else if (birthday==today){
            System.out.println("就是今天");
        }else {
            System.out.println("我的生日已经过了" + (today - birthday) + "天");
        }
        //System.out.println("yesterday is:"+format.format(cal.getTime()));
    }
}
